package ntd.util.config.common.enums.data;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import ntd.util.config.common.enums.BaseEnumInterface;

/**
 * @author /
 */
@Slf4j
@AllArgsConstructor
public enum EnumDataSourceType implements BaseEnumInterface {

    /** mysql */
    MYSQL("mysql", "com.mysql.cj.jdbc.Driver"),

    /** oracle */
    ORACLE("oracle", "oracle.jdbc.driver.OracleDriver"),

    /** sql server */
    SQLSERVER("sqlserver", "com.microsoft.sqlserver.jdbc.SQLServerDriver"),

    /** h2 */
    H2("h2", "org.h2.Driver"),

    /** phoenix */
    PHOENIX("phoenix", "org.apache.phoenix.jdbc.PhoenixDriver"),

    /** mongo */
    MONGODB("mongo", "mongodb.jdbc.MongoDriver"),

    /** sql4es */
    ELASTICSEARCH("sql4es", "nl.anchormen.sql4es.jdbc.ESDriver"),

    /** presto */
    PRESTO("presto", "com.facebook.presto.jdbc.PrestoDriver"),

    /** moonbox */
    MOONBOX("moonbox", "moonbox.jdbc.MbDriver"),

    /** cassandra */
    CASSANDRA("cassandra", "com.github.adejanovski.cassandra.jdbc.CassandraDriver"),

    /** click house */
    CLICKHOUSE("clickhouse", "ru.yandex.clickhouse.ClickHouseDriver"),

    /** kylin */
    KYLIN("kylin", "org.apache.kylin.jdbc.Driver"),

    /** vertica */
    VERTICA("vertica", "com.vertica.jdbc.Driver"),

    /** sap */
    HANA("sap", "com.sap.db.jdbc.Driver"),

    /** impala */
    IMPALA("impala", "com.cloudera.impala.jdbc41.Driver");

    @Getter
    private String feature;
    @Getter
    private String driver;

    public static final String JDBC_URL_PREFIX = "jdbc:";

    public static EnumDataSourceType urlOf(String jdbcUrl) {
        String url = jdbcUrl.toLowerCase().trim();
        for (EnumDataSourceType enumDataSourceType : values()) {
            if (url.startsWith(JDBC_URL_PREFIX + enumDataSourceType.feature)) {
                return enumDataSourceType;
            }
        }
        return null;
    }

    public String jdbcPrefix() {
        return JDBC_URL_PREFIX + this.feature + "://";
    }

    @Override
    public String getName() {
        return this.name();
    }

    @Override
    public String getValue() {
        return this.name();
    }
}
